package fr.bull.learn.thread.util;

import java.util.concurrent.TimeUnit;

/**
 * Use this with start/stop method
 * 
 * @author Rouviere-X
 *
 */
public class Chrono {

	long start;
	long stop;
	
	public Chrono(){
		start =0L;
		stop = 0L;
	}
	
	/**
	 * Start the stopwatch
	 * @return
	 */
	public long start() {
		start = System.currentTimeMillis();
		return start;
	}
	
	/**
	 * Stop the stopwatch
	 * @return
	 */
	public long stop() {
		stop = System.currentTimeMillis();
		return stop;
	}
	
	/**
	 * Millisec time
	 */
	public String toString() {
		long tm = stop - start;
		long sec = TimeUnit.SECONDS.convert(tm, TimeUnit.MILLISECONDS);
		long mn = TimeUnit.MINUTES.convert(tm, TimeUnit.MILLISECONDS);
		long h = TimeUnit.HOURS.convert(tm, TimeUnit.MILLISECONDS);
		return "("+tm+")="+h+":"+mn+":"+sec+"'"+tm % 1000;
	}
}
